package gsp420.game;

import java.awt.Graphics;

public class Tile
{
	char[][] map = new char[Rules.TILE_SIZE][Rules.TILE_SIZE];
	int col, row;
	int type;

	void init(int a_type, int a_col, int a_row)
	{
		col = a_col;
		row = a_row;
		type = a_type;
		if(type >= 0)
		{
			for (int y = 0; y < map.length; ++y)
			{
				for (int x = 0; x < map[y].length; ++x)
				{
					map[y][x] = Rules.TILE_MAP[type][y][x];
				}
			}
		}
	}

	void rotateCW()
	{
		char[][] m = new char[Rules.TILE_SIZE][Rules.TILE_SIZE];
		// char[][] m = new char[TILE_SIZE][];
		// for(int i = 0; i < m.length; ++i)
		// m[i] = new char[TILE_SIZE];
		// copy a x/y mirror
		for (int y = 0; y < m.length; ++y)
		{
			for (int x = 0; x < m[y].length; ++x)
			{
				m[y][x] = map[x][y];
			}
		}
		// put the horizontal flip onto the original
		for (int y = 0; y < m.length; ++y)
		{
			for (int x = 0; x < m[y].length; ++x)
			{
				map[y][x] = m[y][(Rules.TILE_SIZE - 1) - x];
			}
		}
	}

	/**
	 * this will draw a tile that is {@link #TILE_SIZE}x{@link #TILE_SIZE} big
	 * @param g the graphics context to draw to
	 * @param a_x pixel coordinate to start drawing at
	 * @param a_y
	 * @param a_tW tile width
	 * @param a_tH tile height
	 */
	void draw(Graphics g, int a_x, int a_y, int a_tW, int a_tH)
	{
		for (int y = 0; y < map.length; ++y)
		{
			for (int x = 0; x < map[y].length; ++x)
			{
				if (map[y][x] != '.')
				{
					g.fillRect(a_x + x * a_tW, a_y + y * a_tH, a_tW, a_tH);
				}
			}
		}
	}
}
